package com.linran.utils.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;

public class DateUtil {
    public static void main(String[] args) throws ParseException {
        String queryTime = "20200303T160000Z";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
        Date date = simpleDateFormat.parse(queryTime);
        Instant instant = date.toInstant();

        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

        System.out.println(localDateTime.getYear());
        int value = localDateTime.getDayOfWeek().getValue();
        LocalDateTime monday = localDateTime.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1).withHour(0).withMinute(0).withSecond(0);
        LocalDateTime sunday = localDateTime.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).minusDays(1).withHour(23).withMinute(59).withSecond(59);
        System.out.println(value+"--本周一: " + monday);
        System.out.println(value+"--本周日: " + sunday);

        System.out.println(LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN).format(DateTimeFormatter.ISO_DATE_TIME));
    }
}
